#include<iostream>
#include<cstdio>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>


std::string myenv = "HELLO=LINUX";
extern char* *environ;

int main()
{

    putenv((char*)myenv.c_str());
    pid_t id = fork();
    if(id == 0)
    {
        char *const argv[] = {
            (char*) "other",
            nullptr
        };

        //char *const argv[] = {
        //    (char*)"ls",
        //    (char*)"--color",
        //    (char*)"-a",
        //    (char*)"-l",
        //    nullptr
        //};

       

        (void)argv;
        execvpe("./other",argv,environ);
    
//        execl("./other","other",nullptr);

       // execvp("ls",argv);
        //execlp("ls","ls","--color","-a","-l",nullptr);

      //  execv("/usr/bin/ls",argv);

    //    // child
    //    sleep(3);
    //    execl("/bin/ls","ls","-l","--color","-a",nullptr);
    //    exit(1);
    }

    // father
    pid_t rid = waitpid(id,nullptr,0);
    if(rid > 0)
    {
        printf("wait sub process success\n");
    }

//    printf("myexec,pid:%d\n",getpid());
//    int n = execl("/bin/lsss","lsss","-l","-a",nullptr);
//    printf("excel return val:%d\n",n);
//
    //execl("./other","other",nullptr);

    //execl("/bin/ls","ls","-l","-a",nullptr);
    return 0;
}
